package com.hinnotek.amoeba.viewmodels


import androidx.lifecycle.viewModelScope
import com.hinnotek.amoeba.base.BaseBean
import com.hinnotek.amoeba.bean.old.*
import com.hinnotek.amoeba.bean.old.AmountAllocatedBean
import com.hinnotek.amoeba.bean.old.AmeobaCustomerListBean
import com.hinnotek.amoeba.bean.old.ProjectByCustomerBean
import com.hinnotek.amoeba.repo.PublicInterfaceRepo
import com.lee.common.base.BaseViewModel
import com.lee.common.network.net.StateLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class PublicInterfaceViewModel @Inject constructor(private val publicInterfaceRepo: PublicInterfaceRepo) :
    BaseViewModel() {

    val productListBean = StateLiveData<MutableList<ProductListBean>>()
    val productManagamentData = StateLiveData<MutableList<ProductManagamentBean>>()
    val ptAmoebaByCustomerData = StateLiveData<MutableList<ProjectByCustomerBean>>()
    val ptAmoebaCustomerData = StateLiveData<MutableList<AmibaProjectListBean>>()
    val companyContractiveData = StateLiveData<MutableList<CompanyContractNumBean>>()
    val amibaSysUserAdminData = StateLiveData<MutableList<AmibaSysUserAdminBean>>()
    val mmibaSysUserAdminData = StateLiveData<MutableList<AmibaSysUserAdminBean>>()
    val amountAllocatedData = StateLiveData<MutableList<AmountAllocatedBean>>()
    val ameobaCustomerListData = StateLiveData<MutableList<AmeobaCustomerListBean>>()
    val addCompanyContractDistributionData = StateLiveData<BaseBean>()
    private val contractTypeAll = StateLiveData<MutableList<ContractTypeAll>>()


    fun getContractTypeAll() :StateLiveData<MutableList<ContractTypeAll>>{
        viewModelScope.launch {
            publicInterfaceRepo.getContractTypeAll(contractTypeAll)
        }
        return contractTypeAll
    }

    fun getProductList():StateLiveData<MutableList<ProductListBean>> {
        viewModelScope.launch {
            publicInterfaceRepo.getProductList(productListBean)
        }
        return productListBean
    }


    fun getProductTypeListByProductId(productId: Int) :StateLiveData<MutableList<ProductManagamentBean>>{
        viewModelScope.launch {
            publicInterfaceRepo.getProductTypeListByProductId(productId, productManagamentData)
        }
        return productManagamentData
    }


    fun getAmibaProjectListByOrgId(orgId: Int): StateLiveData<MutableList<AmibaProjectListBean>> {
        viewModelScope.launch {
            publicInterfaceRepo.getAmibaProjectListByOrgId(orgId, ptAmoebaCustomerData)
        }
        return ptAmoebaCustomerData
    }


    fun getProjectByCustomerId(customerId: Int):StateLiveData<MutableList<ProjectByCustomerBean>> {
        viewModelScope.launch {
            publicInterfaceRepo.getProjectByCustomerId(customerId, ptAmoebaByCustomerData)
        }
        return ptAmoebaByCustomerData
    }

    fun getCompanyContractNumList() {
        viewModelScope.launch {
            publicInterfaceRepo.getCompanyContractNumList(companyContractiveData)
        }
    }

    fun getAmibaSysUserAdminByOrgId(orgId: Int):StateLiveData<MutableList<AmibaSysUserAdminBean>> {
        viewModelScope.launch {
            publicInterfaceRepo.getAmibaSysUserAdminByOrgId(amibaSysUserAdminData)
        }
        return amibaSysUserAdminData
    }


    fun getCompanySysUserAdmin():StateLiveData<MutableList<AmibaSysUserAdminBean>>{
        viewModelScope.launch {
            publicInterfaceRepo.getCompanySysUserAdmin(mmibaSysUserAdminData)
        }
        return mmibaSysUserAdminData
    }

    fun getSysOrgAmibaList(): StateLiveData<MutableList<AmountAllocatedBean>> {
        viewModelScope.launch {
            publicInterfaceRepo.getSysOrgAmibaList(amountAllocatedData)
        }
        return amountAllocatedData
    }

   fun getAmibaCustomerListByOrgId(orgId: Int): StateLiveData<MutableList<AmeobaCustomerListBean>> {
        viewModelScope.launch {
            publicInterfaceRepo.getAmibaCustomerListByOrgId(orgId,ameobaCustomerListData)
        }
        return ameobaCustomerListData
    }

    


    fun addCompanyContractDistribution(
        contractDistributionType: Int,
        orgId: Int,
        orgName: String,
        customerId: Int,
        customerName: String,
        amibaCustomerProjectId: Int,
        projectName: String,
        companyContractId: Int,
        contractNo: String,
        divideMoney: String,
        createUser: String
    ): StateLiveData<BaseBean> {
        viewModelScope.launch {
            publicInterfaceRepo.addCompanyContractDistribution(
                contractDistributionType,
                orgId,
                orgName,
                customerId,
                customerName,
                amibaCustomerProjectId,
                projectName,
                companyContractId,
                contractNo,
                divideMoney,
                createUser, addCompanyContractDistributionData
            )

        }
        return addCompanyContractDistributionData
    }




}